#!/bin/bash

pattern='^([0-9]{1,3}\.){3}[0-9] winip'
ip=$(grep nameserver /etc/resolv.conf | head -n 1 | awk '{print $2}')

if [[ -n $(grep -E "${pattern}" /etc/hosts) ]]; then
    sed -E -i "s/${pattern}/${ip} winip/g" /etc/hosts
else
    echo "${ip} winip" >> /etc/hosts
fi